package admin.controllers;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.OrderModel;

import admin.data.OrderData;

@SuppressWarnings("serial")
public class EditOrderServlet extends HttpServlet {

	private static final Logger log = Logger.getLogger(ListOrderServlet.class
			.getName());

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		try {
			String strOrderId = request.getParameter("id");
			if (strOrderId != null && !strOrderId.isEmpty()) {				
				OrderModel order = OrderData.getById(strOrderId);
				if (order != null && !order.getOrderId().isEmpty()) {
					request.setAttribute("order", order);
					request.getRequestDispatcher("/admin/pages/edit_order.jsp")
							.forward(request, response);
				} else {
					request.getRequestDispatcher("/pages/erro.jsp").forward(
							request, response);
				}
			} else {
				request.getRequestDispatcher("/pages/erro.jsp").forward(
						request, response);
			}

		} catch (Exception e) {
			System.out.println("Error when get get Order detail !");
			log.warning("Error when get get Order detail !");
			log.warning(e.toString());
			e.printStackTrace();
		}

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		System.out.println("Do post Order edit");
	}
}
